from typing import List


class Solution:
    def findTheDistanceValue(self, arr1: List[int], arr2: List[int], d: int) -> int:
        arr2.sort()
        ans = 0
        for num in arr1:
            if self.search(arr2, num - d, num + d):
                ans += 1
        return ans
    
    def search(self, nums: List[int], low: int, high: int) -> bool:
        left, right = 0, len(nums) - 1
        while left <= right:
            mid = (left + right) // 2
            if nums[mid] >= low and nums[mid] <= high:
                return False
            if nums[mid] < low:
                left = mid + 1
            else:
                right = mid - 1
        return True
      